/**
 * Copyright (c) 2009 Koder Chen. All Rights Reserved.
 *
 * tool.h
 * The file declares the methods used to help the system. It includes
 * some functions to manipulate the memory's allocation, and free.
 *
 *  Author: chenfuhan
 * Created: 2009-6-1
 * Version: 1.0
 */
#ifndef __RSA_TOOL_H__
#define __RSA_TOOL_H__

#include <windows.h>

#include "type.h"

extern i32_t MAX_BITS;
extern i32_t MAX_BYTES;

/** 
 * used to allocate unsigned byte array for the user
 * 
 * @param bytes the number of bytes to be allocated
 * @return the new created bytes array
 */
i8_pt rsa_malloc_byte(u32_t bytes);

/**
 * used to allocate signed byte array for the caller
 *
 * @param bytes the number of bytes to be allocated
 * @return the new created bytes array
 */
u8_pt rsa_malloc_ubyte(u32_t bytes);

/**
 * used to allocate signed int array for the caller
 *
 * @param bytes the number of integers to be allocated
 * @return the new created integers array
 */
i32_pt rsa_malloc_int(u32_t ints);

/**
 * used to allocate unsigned signed integer array for the caller
 *
 * @param bytes the number of integer to be allocated
 * @return the new created integers array
 */
u32_pt rsa_malloc_uint(u32_t ints);

/**
 * used to generate a 'real' random integer
 */
i32_t rsa_rand();

// the macro is used to free the allocated memory
#define rsa_free(p) if(p) {free(p);p=NULL;}
#define rsa_default_malloc() rsa_malloc_ubyte(MAX_BYTES);
#define rsa_max(a, b) (a>b?a:b)

#endif // __RSA_TOOL_H__
